Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Refactor common utils out of ML plugin to XPack.Core #39976

Conversation

benwtrent
Copy link
Member

3 new abstract classes to aid in getting resources.

minor refactors required for such, moved QueryPage, ExpandedIdsMatcher, and PageParams into xpack.core.action.util.

Refactored some of the ML responses. More refactoring will have to be done to rewrite the transports to take advantage of the new abstract class, but did not want this PR to become thousands of lines of changes.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/ml-core

Copy link

@hendrikmuhs hendrikmuhs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just 1 comment/opinion

@@ -38,7 +37,7 @@
public QueryPage(List<T> results, long count, ParseField resultsField) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devils advocate: as we are moving this into a more prominent place, we should discuss the naming of this, I think QueryPage doesn't fit. It's rather a ResultPage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, definitely a possibility. I think the name QueryPage is an artifact of indicating that "This is the results of a Query", but ResultPage does give a broader indication as there is nothing restricting the class.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dimitris-athanasiou ^^ what say you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would even say it is just a Page :-) However, changing this might cause BWC problems, at least on the HLRC and transport level.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this change is already breaking for transport client users (so I added the >breaking-java label). To move a class from one package to another is not too hard to cope with for a developer with an IDE, as the IDE will find the class of the same name in its new place. But to change both the package and the name of a class in a refactoring is quite unfriendly. Plus if the class is renamed server-side then the HLRC equivalent should be renamed to match, and that means we cause work for HLRC users as well as transport client users (as well as extra work for ourselves changing the HLRC docs). So I am also of the opinion that we should stick with the current name even if it isn't perfect.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see (a) QueryPage being used in HLRC.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see (a) QueryPage being used in HLRC.

Yes, that's true. The HLRC responses just contain Java Lists. So we didn't maintain the interface for response objects between the transport client and the HLRC. I thought we had. Sorry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, we've already stepped away from it there with the AbstractResultResponse. I'm glad we did that :-)

@dimitris-athanasiou
Copy link
Contributor

@benwtrent I would suggest that this PR has at least one implementation of the transport action. This will also enable testing all that logic. For simplicity, you could start with the get-filters action. It should be straightforward (similar to the implementation of this in the df-analytics branch).

@hendrikmuhs
Copy link

As others already pointed out, I think this might be a risky change. I therefore bring up the option to introduce the abstractions in core but not to immediately migrate existing ML API's to it. We will use the new abstractions for the new functionality. This gives us time and freedom to stabilize the new abstractions without BWC pain. At a later point we can migrate ML API's after proper testing.

@droberts195
Copy link
Contributor

I don't think it's that risky, although I do think we'll find it's not generic enough in the future.

We have YAML tests that exercise all the REST endpoints that correspond to the refactored actions, so they prove that this change has not broken the existing REST endpoints. I also think if we develop new abstractions with a plan to migrate existing endpoints to them after 7.1 but don't actually do that for 7.1 then it's more likely to mean BWC headaches or never migrating the existing endpoints to the new abstractions.

There are 3 new abstract classes here, for the request, response and transport action. The request and response abstract classes are the simplest and least likely to cause problems. The abstract transport action is the one that's most likely to cause grief in the future. One thing I can see that's missing is for the ExpandedIdsMatcher to have some sort of aliases functionality. For jobs we have job groups, which work like aliases do for indices. But it's not unimaginable in the future that we'd want something similar for some other type of request, maybe transform groups or something. So that makes me think that in the future we'll want ExpandedIdsMatcher to be an interface that the abstract transport action's constructor takes as an argument rather than a concrete class. Then the job transport actions can pass in one that understands how to expand job groups. However, making this change in the future won't affect any public APIs.

I also think that we will find actions where the request and response classes can extend these abstract classes but the transport action cannot, due to having to do something differently. But I don't think that's a problem.

I do agree with @dimitris-athanasiou that it would be best to implement one transport action that extends the abstract transport action just to make sure it is usable in at least one case. But after that I'd be happy to merge this PR.


public abstract class AbstractGetResourcesRequest extends ActionRequest {

public static final String ALLOW_NO_RESOURCES = "allow_no_resources";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bit too abstract to be exposed to end users. Where we've exposed this in the past it's been in more targeted parameters like allow_no_jobs. So I think each group of classes that extend this class should define their own parameter rather than the abstract class suggesting one.

}
getListRequest.setAllowNoResources(restRequest.paramAsBoolean(ALLOW_NO_RESOURCES, true));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it has moved beyond refactoring to adding new functionality. I would say that this PR should just hardcode true here, as that's what the behaviour was before. (If we were to have a parameter to say finding no filters was unacceptable then maybe we'd want to call it allow_no_filters.)

Copy link
Contributor

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@dimitris-athanasiou dimitris-athanasiou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@benwtrent
Copy link
Member Author

run elasticsearch-ci/1

@benwtrent benwtrent merged commit b0d7782 into elastic:master Mar 13, 2019
@benwtrent benwtrent deleted the feature/x-pack-provide-abstract-resource-action-transport branch March 13, 2019 19:23
benwtrent added a commit to benwtrent/elasticsearch that referenced this pull request Mar 13, 2019
)

* [ML] Refactor common utils out of ML plugin to XPack.Core

* implementing GET filters with abstract transport

* removing added rest param

* adjusting how defaults can be supplied
benwtrent added a commit that referenced this pull request Mar 13, 2019
…40009)

* [ML] Refactor common utils out of ML plugin to XPack.Core

* implementing GET filters with abstract transport

* removing added rest param

* adjusting how defaults can be supplied
@benwtrent
Copy link
Member Author

@jasontedor ping This PR added some commonly useful code to xpack.core.action

dimitris-athanasiou added a commit to dimitris-athanasiou/elasticsearch that referenced this pull request Mar 25, 2020
When get filters is called without setting the `size`
paramter only up to 10 filters are returned. However,
100 filters should be returned. This commit fixes this
and adds an integ test to guard it.

It seems this was accidentally broken in elastic#39976.

Closes elastic#54206
dimitris-athanasiou added a commit that referenced this pull request Mar 26, 2020
When get filters is called without setting the `size`
paramter only up to 10 filters are returned. However,
100 filters should be returned. This commit fixes this
and adds an integ test to guard it.

It seems this was accidentally broken in #39976.

Closes #54206
dimitris-athanasiou added a commit to dimitris-athanasiou/elasticsearch that referenced this pull request Mar 26, 2020
When get filters is called without setting the `size`
paramter only up to 10 filters are returned. However,
100 filters should be returned. This commit fixes this
and adds an integ test to guard it.

It seems this was accidentally broken in elastic#39976.

Closes elastic#54206

Backport of elastic#54207
dimitris-athanasiou added a commit that referenced this pull request Mar 26, 2020
When get filters is called without setting the `size`
paramter only up to 10 filters are returned. However,
100 filters should be returned. This commit fixes this
and adds an integ test to guard it.

It seems this was accidentally broken in #39976.

Closes #54206

Backport of #54207
dimitris-athanasiou added a commit that referenced this pull request Mar 26, 2020
When get filters is called without setting the `size`
paramter only up to 10 filters are returned. However,
100 filters should be returned. This commit fixes this
and adds an integ test to guard it.

It seems this was accidentally broken in #39976.

Closes #54206

Backport of #54207
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants